import { defineStore } from 'pinia';
import api from "@/api/index.js";

export const useCouponStore = defineStore('discountCoupon', {
	state: () => {
		return {
			status: '',
			total: 0,
			list: [],

			loadingState: {
				default: false,
				loading: false,
				stop: false,
				pullup: false,
			}
		}
	},

	getters: {

	},

	actions: {
		// 重置store
		RESET_STORE() {
			this.$reset();
		},

		// 设置status
		SET_STATUS(value) {
			this.status = value;
			this.getList(value);
		},

		// 获取列表数据
		async getList(status) {
			this.loadingState.default = true;
			this.loadingState.stop = false;
			this.list = [];

			// const res = await this.$api.coupon_api.list({
			// 	status
			// });
			const res = {
				data: {
					data: [{
						type_id: 1,
						status: 2,
						discount: 8.8,
						min_amount: 8.9,
						expire_date: '2024-10-10',
						type_name: '满减券'
					},{
						type_id: 2,
						status: 2,
						discount: 9.5,
						min_amount: 50,
						expire_date: '2024-10-12',
						type_name: '折扣券'
					}]
				}
			}

			this.list = res.data.data || [];
			this.loadingState.default = false;
			this.loadingState.stop = !!this.list.length;
		}
	},
})